package com.basic.java.threads.status;

/**
 * 观测线程状态类
 * 创建时间：2022/4/19 21:06
 *
 * @author gejin
 */
public class TestThreadStatus {
    public static void main(String[] args) throws InterruptedException {
        // 新建线程
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("/////");
        });

        // 输出线程线程状态
        System.out.println(thread.getState()); // New

        // 启动线程
        thread.start();
        System.out.println(thread.getState()); //Run

        // 只要线程不停止， 就一直输出
        while (thread.getState() != Thread.State.TERMINATED) {
            Thread.sleep(100);
            System.out.println(thread.getState());
        }

    }
}
